package org.wendu.wdoa.security.user.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.wendu.wdoa.common.Result;
import org.wendu.wdoa.security.role.dto.FunDto;
import org.wendu.wdoa.security.role.dto.RoleQueryDto;
import org.wendu.wdoa.security.user.dto.UserQueryDto;
import org.wendu.wdoa.security.user.dto.roleDto;
import org.wendu.wdoa.security.user.service.UserService;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserApi {
    @Autowired
    private UserService userService;

    @GetMapping("")
    public Result userList(UserQueryDto pageParam){
        Map<String ,Object> list = userService.getUserList(pageParam);
        return Result.OK(list);
    }

    @GetMapping("/all-userFun")
    public Result userFunList() {
        List<roleDto> funList = userService.getUserFunList();
        return Result.OK(funList);
    }

    @GetMapping("/fun/{u_id}")
    public Result roleFunIds(@PathVariable String u_id) {
        List<Integer> funIds = userService.getUserFunIds(u_id);
        return Result.OK(funIds);
    }

    @PutMapping("fun/{u_id}")
    public Result roleConfirmFuns(@PathVariable String u_id,@RequestBody Integer[] ro_ids) {
        userService.confirmUserFuns(u_id, ro_ids);
        return Result.OK();
    }
}
